import scrapy
from dytt_movies.items import DyttMoviesItem

class MoviesSpider(scrapy.Spider):
    name = "movies"
    allowed_domains = ["btwuji.com"]
    start_urls = ["https://btwuji.com/html/gndy/dyzz/index.html"]

    def parse(self, response):
        # 获取名字和图片
        a_list = response.xpath('//div[@class="co_content8"]//td[2]//a')
        for a in a_list:
            name = a.xpath('./text()').extract_first()
            href = a.xpath('./@href').extract_first()
            url = 'https://btwuji.com'+href
            #print(url)
            yield scrapy.Request(url=url,callback=self.seconde,meta={'name':name})
    def seconde(self,response):
        src = response.xpath('//div[@id="Zoom"]//img/@src').extract_first()
        name = response.meta['name']
        movies = DyttMoviesItem(name=name,src=src)
        yield movies